/*
 * @Description: 根据字符串key返回，给定数据的值
 * @Author: wangqi
 * @Date: 2021-05-06 23:08:11
 * @LastEditTime: 2021-05-08 10:15:31
 */

/*
    data = { a:{ b: { c:100 }}};
    keyName = "a.b.c";
    return => 100
*/

function lookup(data, keyName) {
    if (keyName.includes(".") && keyName != '.') {
        let tmp = data;
        let keys = keyName.split(".");
        for (let i = 0; i < keys.length; i++) {
            tmp = tmp[keys[i]];
        }
        return tmp;
    }
    return data[keyName];
};

export default lookup